package com.xz.courseschedule.controller;

import com.xz.courseschedule.entity.Course;
import com.xz.courseschedule.service.CourseService;
import com.xz.courseschedule.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程管理控制器
 * @Author: zys
 * @CreateTime: 2025-05-24
 */
@Tag(name = "课程管理", description = "课程信息的管理和查询")
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @Operation(summary = "获取课程列表", description = "获取系统中所有课程的信息列表")
    @GetMapping("/getList")
    public Result getList(){
        return courseService.getList();
    }

    @Operation(summary = "根据ID获取课程", description = "根据课程ID获取单个课程的详细信息")
    @Parameter(name = "id", description = "课程ID", required = true)
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        return courseService.getById(id);
    }

    @Operation(summary = "新增课程", description = "添加新的课程到系统中")
    @PostMapping("/add")
    public Result add(@RequestBody Course course){
        return courseService.add(course);
    }

    @Operation(summary = "更新课程", description = "更新指定的课程信息")
    @PutMapping("/update/{id}")
    public Result update(@PathVariable Long id, @RequestBody Course course){
        course.setId(id);
        return courseService.update(course);
    }

    @Operation(summary = "删除课程", description = "根据课程ID删除指定的课程")
    @Parameter(name = "id", description = "课程ID", required = true)
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return courseService.delete(id);
    }

    @Operation(summary = "批量删除课程", description = "根据课程ID列表批量删除课程")
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody Long[] ids){
        return courseService.deleteBatch(ids);
    }
}
